package com.supor.aiot.common.interfaces;

import android.content.Context;

import com.alipay.mobile.common.share.ShareException;
import com.alipay.mobile.framework.service.ShareService;
import com.android.baseconfig.common.utils.Logc;
import com.supor.aiot.common.app.SuporPresenter;

public class ShareListener implements ShareService.ShareActionListener {

    private static final String TAG = "ShareListener";

    private Context mContext;

    public ShareListener(Context context) {
        mContext = context;
    }

    /**
     * 分享成功
     *
     * @param shareType 分享类型
     */
    @Override
    public void onComplete(int shareType) {
        Logc.d(TAG, "onComplete: " + shareType);
        SuporPresenter.getInstance().reportShareStatus(1);
    }

    /**
     * 分享异常
     *  1001用户取消
     *  1002认证失败
     *  1003其他异常
     *  40501应用未安装
     * @param shareType 分享类型
     * @param e         异常信息
     */
    @Override
    public void onException(int shareType, final ShareException e) {
        Logc.i(TAG, "onException: " + e.getStatusCode() + ", " + e.getMessage());
        int errorCode = e.getStatusCode();
        // 当code = USER_CANCEL时，表示用户主动取消分享
        if (ShareException.USER_CANCEL == errorCode) {
            Logc.d(TAG, "onException: cancel");
        }

        SuporPresenter.getInstance().reportShareStatus(errorCode);
    }
}
